import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;

/**
 * WordBee Class
 * Word Bee game class, that creates and holds screens
 * 
 * @author Zong Xiong
 */
public class WordBee extends Game{
	
/***************************************************
 * Fields
 ***************************************************/
	
	// stores and loads scores
	private Preferences prefs;
	
/***************************************************
 * Public Methods
 ***************************************************/
	
	/**
	 * create
	 * called when game is created
	 */
	@Override
	public void create() {
		resetScores();
		setScreen(new MenuScreen(this));
	}
	
/***************************************************
 * Private Methods
 ***************************************************/
	
	/**
	 * resetScores
	 * reset scores to 0 if first time being initialized
	 */
	private void resetScores() {
		// reset scores for normal word games
		prefs = Gdx.app.getPreferences("NormalWordGame");
		if (!prefs.getBoolean("created")) {
			prefs.putBoolean("created", true);
			for (int i = 1; i < 6; i++) {
				prefs.putString("Place"+i+"Name", "");
				prefs.putLong("Place"+i+"Score", 0);
				prefs.flush();
			}
		}
		// reset scores for survival word games
		prefs = Gdx.app.getPreferences("SurvivalWordGame");
		if (!prefs.getBoolean("created")) {
			prefs.putBoolean("created", true);
			for (int i = 1; i < 6; i++) {
				prefs.putString("Place"+i+"Name", "");
				prefs.putLong("Place"+i+"Score", 0);
				prefs.flush();
			}
		}
		// reset scores for time attack word games
		prefs = Gdx.app.getPreferences("TimeAttackWordGame");
		if (!prefs.getBoolean("created")) {
			prefs.putBoolean("created", true);
			for (int i = 1; i < 6; i++) {
				prefs.putString("Place"+i+"Name", "");
				prefs.putLong("Place"+i+"Score", 0);
				prefs.flush();
			}
		}
		// reset scores for destroyer word games
		prefs = Gdx.app.getPreferences("DestroyerWordGame");
		if (!prefs.getBoolean("created")) {
			prefs.putBoolean("created", true);
			for (int i = 1; i < 6; i++) {
				prefs.putString("Place"+i+"Name", "");
				prefs.putLong("Place"+i+"Score", 60000);
				prefs.flush();
			}
		}
	}
}
